import { Map } from 'immutable';
import * as actionTypes from './constants';

const defaultState = Map({
  albums: [], // 专辑
  artists: [], // 歌手
  order: [], //搜索列表顺序 ["songs", "artists", "albums", "playlists"]
  playlists: [], // 歌单
  songs: [], // 单曲
});

export default function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.UPDATE_SEARCH:
      return state.mergeDeep({
        albums: action.result.albums || [],
        artists: action.result.artists || [],
        order: action.result.order || [],
        playlists: action.result.playlists || [],
        songs: action.result.songs || [],
      })
    case actionTypes.RESET_SEARCH:
      return defaultState
    default:
      return defaultState;
  }
}
